package plat_user

import (
	"gitee.com/baizhige/go-server-tempalte/common/auth"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
	"time"
)

type PlatUser struct {
	Id       primitive.ObjectID `bson:"_id,omitempty"`
	Username string             `bson:"username"`
	Password string             `bson:"password"`
	Enable   bool               `bson:"enable"`
	Roles    []string           `bson:"roles"`
}

func (p PlatUser) IdString() string {
	return p.Id.Hex()
}

func (p PlatUser) GetLoginConfig() auth.LoginConfig {
	return auth.LoginConfig{
		TokenKey: "platform",
		Expire:   15 * time.Minute,
	}
}

func (p PlatUser) GetAuthorizations() []string {
	return p.Roles
}

func (p PlatUser) CollectionName() string {
	return "plat_user"
}

func (p PlatUser) GetIndex() []mongo.IndexModel {
	return []mongo.IndexModel{
		{Keys: bson.D{{"username", 1}}, Options: options.Index().SetUnique(true)},
	}
}
